package com.itheima.work;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @auther Macrydy
 * @date 2020/7/3 18:39
 * 1. 请定义一个Student类，属性：姓名、性别、年龄、分数
 * 无参、全参构造方法
 * get/set方法
 * 2. 定义测试类，编写main()方法：
 * //1.定义一个集合
 * List<Student> stuList = new ArrayList<>();
 * stuList.add(new Student(“张三”,”男”,20,88);
 * stuList.add(new Student(“李四”,”女”,19,99);
 * 3. 遍历这个集合，将每个Student对象中的数据按以下格式写到项目根目录下
 * 的student.txt中：
 * 张三,男,20,88
 * 李四,女,19,99
 */
public class Test7 {
    public static void main(String[] args) throws IOException {
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student("张三","男", 20, 88));
        stuList.add(new Student("李四","女", 19, 99));

        FileOutputStream fos = new FileOutputStream("day10IO\\student.txt");
        for (Student student : stuList) {
            fos.write(student.getName().getBytes());
            fos.write(",".getBytes());
            fos.write(student.getSex().getBytes());
            fos.write(",".getBytes());
            fos.write((student.getAge()+"").getBytes());
            fos.write(",".getBytes());
            fos.write((student.getScore()+"").getBytes());
            fos.write("\r\n".getBytes());
        }
    }
}
